<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://www.zkingsoft.com" prefix="matrix"%>
<c:set var="path" value="${pageContext.request.contextPath }" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!-- 本框架基本脚本和样式 -->
<script type="text/javascript"
	src="${path }/resource/js/plugin/jquery-2.1.4.min.js"></script>
<script type="text/javascript"
	src="${path }/resource/js/systools/MBase.js"></script>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
		<!-- 搜索框部分start -->
		<matrix:btn value="PcMenuRecord:search">
<div class="row" >
		<div class="col-sm-12" > 
			<form class="form-inline" id="serchform">
				<div class="form-group mr-20">
				    <input placeholder="请输入开始日期" name="startTime" id="beginTime" type="text" class="form-control datetimepicker">
				    <input placeholder="请输入结束日期" name="endTime" id="endTime" type="text" class="form-control datetimepicker">
					<!--  <input placeholder="请输入关键词" name="" type="text" class="form-control">-->
				</div>
				<button onclick="myGrid.serchData()" type="button"
					class="btn btn-info btn-sm">
					<i class="fa fa-search "></i> 搜索
				</button>
				<button onclick="MForm.reset('#serchform');" type="button" class="btn btn-info btn-sm">
					<i class="fa fa-refresh "></i> 重置
				</button>
			</form>
			</div>
	</div>
		</matrix:btn> 
		<!-- 搜索框部分en -->
		<div class="ibox-content radius-5 mt-5 mpanel">
		
	<div class="row" >
		<div class="col-sm-12" >
			
		<div class="option-bar">
			<matrix:btn value="PcMenuRecord:dels"> 
				<button onclick="myGrid.delItems('menId')" type="button"
					class="btn btn-danger btn-sm">
					<i class="fa fa-trash"></i>批量删除
				</button>
			</matrix:btn>
			
			<matrix:btn value="PcMenuRecord:add"> 
			
				<button onclick="openAdd()" type="button"
					class="btn btn-success btn-sm">
					<i class="fa fa-plus datepicker"></i> 生成本周菜谱
				</button>
			</matrix:btn>
		</div>
		<table id="mgrid">
			<thead>
				<tr>
					<th data-checkbox="true"></th>
					<th data-formatter="MGrid.indexfn" data-align="center"  data-width="30px" >序号</th>
					<th data-field="menBeginTime"  data-formatter="MGrid.getTimeDD" data-sortable="true">开始时间</th>
					<th data-field="menEndTime" data-formatter="MGrid.getTimeDD" data-sortable="true">结束时间</th>
					<th data-field="menManMun" >就餐人数</th>
					<th data-field="menUserId" >生成用户</th>
					<th data-field="menCreateTime" data-formatter="MGrid.getTime" data-sortable="true">操作时间</th>
					<th data-field="menWeekSign" >周数标识</th>
					<th data-align="center"  data-width="195px" data-field="menId" data-formatter="buidOperate">操作</th>
				</tr>
			</thead>
		</table>
	</div>
</div>
</div>
</div>
<script type="text/javascript"
	src="${path }/resource/js/systools/MJsBase.js"></script>
	<script type="text/javascript">
		 var myGrid;
		$(function(){
			var delUrl="";
			<matrix:btn value="PcMenuRecord:del"> 
			delUrl="${path}/admin/pcMenuRecord/del" ;
			</matrix:btn>
			myGrid=MGrid.initGrid({
				 url:"${path}/admin/pcMenuRecord/showList",
				 delUrl:delUrl,
			 });
			MTools.ininDatetimepicker({format:'yyyy-mm-dd'})
			MTools.limitStartEndTime({format:'yyyy-mm-dd'});
			
		});
		
	 	function buidOperate(value, row, index){
			var html = [];
			<matrix:btn value="PcMenuRecord:edit"> 
			html[0] = '<a  onClick="openEdit('+value+')"  title="查看" class="fa fa-edit option"></a>'
			</matrix:btn>
			<matrix:btn value="PcMenuRecord:del"> 
			html[1] = '<a onClick="myGrid.delItem('+value+')" title="删除" class="fa fa-close option text-danger"></a>';
			</matrix:btn>
			return html.join(""); 
		}  
		// 计算当前日期在本月份的周数  
	    Date.prototype.getWeekOfMonth = function(weekStart) {  
		    weekStart = (weekStart || 0) - 0;  
		    if(isNaN(weekStart) || weekStart > 6)  
		        weekStart = 0;  
		    var dayOfWeek = this.getDay();  
		    var day = this.getDate();  
		    return Math.ceil((day - dayOfWeek - 1) / 7) + ((dayOfWeek >= weekStart) ? 1 : 0);  
		}  
//		<matrix:btn value="PcMenuRecord:add"> 
        //生成本周菜谱
        function openAdd(loj) {
			 layer.open({
				type : 2,
				title : "请选择月份周数",
				area : [ MUI.SIZE_S, '300px' ],
				maxmin : true,
				content : [ '${path}/admin/pcMenuRecord/editForm' ]
			})};
			
		function createRecord(loj) {
			//得到当前时间
			var index = layer.load(1, {
						  shade: [0.6,'#fff'] //0.1透明度的白色背景
						});
			var str = loj.split("-");
			var now = new Date();
			var m=str[0];
			now.setMonth(parseInt(m)-1);
			now.setDate(1);
		    var w1 = now.getDay();
		    if (w1 == 0) 
		    	w1 = 7;
		    if (w1 != 1) 
		    	d1 = 7 - w1 + 2;
		    else 
		    	d1 = 1;
			now.setDate(d1+7*(parseInt(str[1])-1));
			var end = new Date(now.getTime()+7*24*3600*1000);
			//当前日
			var nowDay = now.getDate();  
			//得到年份
			var year = now.getFullYear();
			var nowYear = now.getYear();             
			//得到月份
			var month = now.getMonth();	
			//今天是本周的第几天
			var nowDayOfWeek = now.getDay();	
			//获得本周的开始日期        
			var weekStartDate = new Date(year, month, nowDay - nowDayOfWeek);      
			//获得本周的结束日期     
		    var weekEndDate = new Date(year, month, nowDay + (6 - nowDayOfWeek)); 
			var weekSign = year.toString()+(m).toString()+str[1];
			var data ={menBeginTime:weekStartDate,menEndTime:weekEndDate,menManMun:null,menUserId:null,menCreateTime:now,menWeekSign:weekSign};
			   $.AjaxProxy({p:data, a:false  }).invoke("${path}/admin/pcMenuRecord/addOrModify", function(loj) {
				   layer.close(index);
				   layer.msg("生成菜谱成功", {
						icon : 1,time:1000
					});
				 myGrid.serchData();
			}); 
		}
		//</matrix:btn>
		
		//打开编辑界面
 		<matrix:btn value="PcMenuRecord:edit"> 
		function openEdit(id) {
			layer.full( layer.open({
				type : 2,
				title : " ",
				area : [ MUI.SIZE_L, '400px' ],
				maxmin : true,
				content : [ '${path}/admin/pcMenuDetail/showList?id=' + id ]
			}));
		}
		</matrix:btn>
		
		function findByTime(){
			var data ={};
			$.AjaxProxy({p:data, a:false ,c : false }).invoke("${path}/admin/pcMenuRecord/addOrModify", function(loj) {
			    myGrid.serchData();
			});	
		}
		
	</script>
</body>
</html>
